export interface LyricLine { time: number; text: string; }

export function parseLrc(lrc: string): LyricLine[] {
  const lines = lrc.split(/\n|\r/);
  const result: LyricLine[] = [];
  const timeExp = /\[(\d{2}):(\d{2})\.(\d{2,3})]/;
  lines.forEach(line => {
    const match = timeExp.exec(line);
    if (match) {
      const min = parseInt(match[1]);
      const sec = parseInt(match[2]);
      const ms = parseInt(match[3].padEnd(3, '0'));
      const time = min * 60 + sec + ms / 1000;
      const text = line.replace(timeExp, '').trim();
      if (text) result.push({ time, text });
    }
  });
  return result.sort((a, b) => a.time - b.time);
}
